#ifndef __ISO_POSIX_HINT_H__
#define __ISO_POSIX_HINT_H__

class help_introduce
{
    // man help http://man7.org/linux/man-pages/man1/man.1.html
    // 1 表示用户命令和守护进程。
    // 2 表示系统调用和内核服务。
    // 3 表示子例程。
    // 4 表示特殊文件、设备驱动程序和硬件。
    // 5 表示配置文件。
    // 6 表示游戏。
    // 7 表示杂项命令。
    // 8 表示管理命令和守护进程。
    // Example:
    // man man
    // man 2 open

    // http://gcc.gnu.org/onlinedocs/
    //#include <unistd.h>
    //#include <sys/socket.h>
	//#include <sys/stat.h>
	//#include <sys/mman.h>
};


class help_language
{

};

class help_library
{

};

class help_faq{
/**
	1.Segmentation fault (core dumped),core file not found?
	 ulimit -a; //check core file size should set none 0
	 ulimit -c unlimited;  //remove limilit core file size
	 gdb ./sample core
	 (gdb) bt

**/
};
class help_header
{
// https://pubs.opengroup.org/onlinepubs/9699919799/idx/head.html

//===============basic header file compatible with std c==============
// assert.h       - verify program assertion
// complex.h      - complex arithmetic
// ctype.h        - character types
// errno.h        - system error numbers
// float.h        - floating types
// inttypes.h     - fixed size integer types
// iso646.h       - alternative spellings
// limits.h       - defined constants
// locale.h       - category macros
// math.h         - mathematical declarations
// setjmp.h       - stack environment declarations
// signal.h       - signals
// stdarg.h       - handle variable argument list
// stdbool.h      - boolean type and values
// stddef.h       - standard type definitions
// stdint.h       - integer types
// stdio.h        - standard buffered input/output
// stdlib.h       - standard library definitions
// string.h       - string operations
// time.h         - time types
// ulimit.h       - ulimit commands
// wchar.h        - character handling
// wctype.h       - character classification and mapping utilities

//===============posix head files================================
// <aio.h>          - asynchronous input and output. 					@Ref { module_aio }
// <arpa/inet.h>    - definitions for internet operations.				@Ref { module_inet }
// <cpio.h>         - cpio archive values.
// <dirent.h>       - format of directory entries.  					@Ref { module_dir }
// <fcntl.h>        - file control options.								@Ref { module_file }
// <fenv.h>         - point environment.
// <fmtmsg.h>       - message display structures.
// <fnmatch.h>      - matching types.
// <ftw.h>          - file tree traversal.
// <glob.h>         - matching types.
// <grp.h>          - group structure.
// <iconv.h>        - codeset conversion facility.
// <langinfo.h>     - language information constants.
// <libgen.h>       - definitions for pattern matching functions.
// <monetary.h>     - monetary types.
// <mqueue.h>       - message queues (REALTIME).
// <ndbm.h>         - definitions for ndbm database operations.
// <netdb.h>        - definitions for network database operations.
// <net_if.h>       - sockets local interfaces.
// <netinet/in.h>   - Internet address family.
// <netinet/tcp.h>  - definitions for the Internet TCP.
// <nl_types.h>     - data types.
// <poll.h>         - definitions for the poll() function.
// <pthread.h>      - threads.										@Ref { module_pthread }
// <pwd.h>          - password structure.
// <regex.h>        - regular expression matching types.
// <sched.h>        - execution scheduling.
// <search.h>       - search tables.
// <semaphore.h>    - semaphores.
// <spawn.h>        - spawn (ADVANCED REALTIME)
// <strings.h>      - string operations
// <stropts.h>      - STREAMS interface (STREAMS)

// <sys/ipc.h>      - XSI interprocess communication access structure
// <syslog.h>       - definitions for system error logging
// <sys/mman.h>     - memory management declarations
// <sys/msg.h>      - XSI message queue structures
// <sys/resource.h> - definitions for XSI resource operations
// <sys/select.h>   - select types
// <sys/sem.h>      - XSI semaphore facility
// <sys/shm.h>      - XSI shared memory facility
// <sys/socket.h>   - main sockets header    						@Ref{ module_IPC_sockets }
// <sys/stat.h>     - data returned by the stat() function  		@Ref{ module_file }
// <sys/statvfs.h>  - VFS File System information structure
// <sys/time.h>     - time types
// <sys/times.h>    - file access and modification times structure
// <sys/types.h>    - data types									 @Ref{ h_sys_types }
// <sys/uio.h>      - definitions for vector I/O operations
// <sys/un.h>       - definitions for UNIX domain sockets
// <sys/utsname.h>  - system name structure
// <sys/wait.h>     - declarations for waiting

// <tar.h>          - extended tar definitions
// <termios.h>      - define values for termios
// <tgmath.h>       - generic macros
// <trace.h>        - tracing
// <utime.h>        - access and modification times structure
// <utmpx.h>        - user accounting database definitions
// <wordexp.h>      - expansion types
// <unistd.h>       - Various essential POSIX functions and constants
// <dlfcn.h>        - Dynamic linking                                 @Ref { module_dlfcn }

/**
（1）string，字符串处理 
（2）signal，信号处理 
（3）dlfcn，管理共享库的动态加载 
（4）direct，文件目录操作 
（5）elf，共享库的动态加载器，也即interpreter 
（6）iconv，不同字符集的编码转换 
（7）inet，socket接口的实现 
（8）intl，国际化，也即gettext的实现 
（9）io 
（10）linuxthreads 
（11）locale，本地化 
（12）login，虚拟终端设备的管理，及系统的安全访问 
（13）malloc，动态内存的分配与管理 
（14）nis 
（15）stdlib，其它基本功能 
**/
};
#define ref_errno_base {} // <errno-base.h>

#define	EPERM		 1	/* Operation not permitted */
#define	ENOENT		 2	/* No such file or directory */
#define	ESRCH		 3	/* No such process */
#define	EINTR		 4	/* Interrupted system call */
#define	EIO		     5	/* I/O error */
#define	ENXIO		 6	/* No such device or address */
#define	E2BIG		 7	/* Argument list too long */
#define	ENOEXEC		 8	/* Exec format error */
#define	EBADF		 9	/* Bad file number */
#define	ECHILD		10	/* No child processes */
#define	EAGAIN		11	/* Try again */
#define	ENOMEM		12	/* Out of memory */
#define	EACCES		13	/* Permission denied */
#define	EFAULT		14	/* Bad address */
#define	ENOTBLK		15	/* Block device required */
#define	EBUSY		16	/* Device or resource busy */
#define	EEXIST		17	/* File exists */
#define	EXDEV		18	/* Cross-device link */
#define	ENODEV		19	/* No such device */
#define	ENOTDIR		20	/* Not a directory */
#define	EISDIR		21	/* Is a directory */
#define	EINVAL		22	/* Invalid argument */
#define	ENFILE		23	/* File table overflow */
#define	EMFILE		24	/* Too many open files */
#define	ENOTTY		25	/* Not a typewriter */
#define	ETXTBSY		26	/* Text file busy */
#define	EFBIG		27	/* File too large */
#define	ENOSPC		28	/* No space left on device */
#define	ESPIPE		29	/* Illegal seek */
#define	EROFS		30	/* Read-only file system */
#define	EMLINK		31	/* Too many links */
#define	EPIPE		32	/* Broken pipe */
#define	EDOM		33	/* Math argument out of domain of func */
#define	ERANGE		34	/* Math result not representable */

#define	EDEADLK		35	/* Resource deadlock would occur */
#define	ENAMETOOLONG 36	/* File name too long */
#define	ENOLCK		37	/* No record locks available */
#define	ENOSYS		38	/* Function not implemented */
#define	ENOTEMPTY	39	/* Directory not empty */
#define	ELOOP		40	/* Too many symbolic links encountered */
#define	EWOULDBLOCK	EAGAIN	/* Operation would block */
#define	ENOMSG		42	/* No message of desired type */
#define	EIDRM		43	/* Identifier removed */
#define	ECHRNG		44	/* Channel number out of range */
#define	EL2NSYNC	45	/* Level 2 not synchronized */
#define	EL3HLT		46	/* Level 3 halted */
#define	EL3RST		47	/* Level 3 reset */
#define	ELNRNG		48	/* Link number out of range */
#define	EUNATCH		49	/* Protocol driver not attached */
#define	ENOCSI		50	/* No CSI structure available */
#define	EL2HLT		51	/* Level 2 halted */
#define	EBADE		52	/* Invalid exchange */
#define	EBADR		53	/* Invalid request descriptor */
#define	EXFULL		54	/* Exchange full */
#define	ENOANO		55	/* No anode */
#define	EBADRQC		56	/* Invalid request code */
#define	EBADSLT		57	/* Invalid slot */

#define	EDEADLOCK	EDEADLK

#define	EBFONT		59	/* Bad font file format */
#define	ENOSTR		60	/* Device not a stream */
#define	ENODATA		61	/* No data available */
#define	ETIME		62	/* Timer expired */
#define	ENOSR		63	/* Out of streams resources */
#define	ENONET		64	/* Machine is not on the network */
#define	ENOPKG		65	/* Package not installed */
#define	EREMOTE		66	/* Object is remote */
#define	ENOLINK		67	/* Link has been severed */
#define	EADV		68	/* Advertise error */
#define	ESRMNT		69	/* Srmount error */
#define	ECOMM		70	/* Communication error on send */
#define	EPROTO		71	/* Protocol error */
#define	EMULTIHOP	72	/* Multihop attempted */
#define	EDOTDOT		73	/* RFS specific error */
#define	EBADMSG		74	/* Not a data message */
#define	EOVERFLOW	75	/* Value too large for defined data type */
#define	ENOTUNIQ	76	/* Name not unique on network */
#define	EBADFD		77	/* File descriptor in bad state */
#define	EREMCHG		78	/* Remote address changed */
#define	ELIBACC		79	/* Can not access a needed shared library */
#define	ELIBBAD		80	/* Accessing a corrupted shared library */
#define	ELIBSCN		81	/* .lib section in a.out corrupted */
#define	ELIBMAX		82	/* Attempting to link in too many shared libraries */
#define	ELIBEXEC	83	/* Cannot exec a shared library directly */
#define	EILSEQ		84	/* Illegal byte sequence */
#define	ERESTART	85	/* Interrupted system call should be restarted */
#define	ESTRPIPE	86	/* Streams pipe error */
#define	EUSERS		87	/* Too many users */
#define	ENOTSOCK	88	/* Socket operation on non-socket */
#define	EDESTADDRREQ	89	/* Destination address required */
#define	EMSGSIZE	90	/* Message too long */
#define	EPROTOTYPE	91	/* Protocol wrong type for socket */
#define	ENOPROTOOPT	92	/* Protocol not available */
#define	EPROTONOSUPPORT	93	/* Protocol not supported */
#define	ESOCKTNOSUPPORT	94	/* Socket type not supported */
#define	EOPNOTSUPP	95	/* Operation not supported on transport endpoint */
#define	EPFNOSUPPORT	96	/* Protocol family not supported */
#define	EAFNOSUPPORT	97	/* Address family not supported by protocol */
#define	EADDRINUSE	98	/* Address already in use */
#define	EADDRNOTAVAIL	99	/* Cannot assign requested address */
#define	ENETDOWN	100	/* Network is down */
#define	ENETUNREACH	101	/* Network is unreachable */
#define	ENETRESET	102	/* Network dropped connection because of reset */
#define	ECONNABORTED	103	/* Software caused connection abort */
#define	ECONNRESET	104	/* Connection reset by peer */
#define	ENOBUFS		105	/* No buffer space available */
#define	EISCONN		106	/* Transport endpoint is already connected */
#define	ENOTCONN	107	/* Transport endpoint is not connected */
#define	ESHUTDOWN	108	/* Cannot send after transport endpoint shutdown */
#define	ETOOMANYREFS	109	/* Too many references: cannot splice */
#define	ETIMEDOUT	110	/* Connection timed out */
#define	ECONNREFUSED	111	/* Connection refused */
#define	EHOSTDOWN	112	/* Host is down */
#define	EHOSTUNREACH	113	/* No route to host */
#define	EALREADY	114	/* Operation already in progress */
#define	EINPROGRESS	115	/* Operation now in progress */
#define	ESTALE		116	/* Stale NFS file handle */
#define	EUCLEAN		117	/* Structure needs cleaning */
#define	ENOTNAM		118	/* Not a XENIX named type file */
#define	ENAVAIL		119	/* No XENIX semaphores available */
#define	EISNAM		120	/* Is a named type file */
#define	EREMOTEIO	121	/* Remote I/O error */
#define	EDQUOT		122	/* Quota exceeded */

#define	ENOMEDIUM	123	/* No medium found */
#define	EMEDIUMTYPE	124	/* Wrong medium type */
#define	ECANCELED	125	/* Operation Canceled */
#define	ENOKEY		126	/* Required key not available */
#define	EKEYEXPIRED	127	/* Key has expired */
#define	EKEYREVOKED	128	/* Key has been revoked */
#define	EKEYREJECTED	129	/* Key was rejected by service */

/* for robust mutexes */
#define	EOWNERDEAD	130	/* Owner died */
#define	ENOTRECOVERABLE	131	/* State not recoverable */

#define ERFKILL		132	/* Operation not possible due to RF-kill */

#define EHWPOISON	133	/* Memory page has hardware error */

 

/********************************************************************************
								global definition
********************************************************************************/
/********************************************************************************
								<sys/types.h> - data types
********************************************************************************/

class h_sys_types{
};

typedef language_c_type blkcnt_t; 	///< Used for file block counts.
typedef language_c_type blksize_t;	///< Used for block sizes.
typedef language_c_type clock_t;	///< Used for system times in clock ticks or CLOCKS_PER_SEC; see <time.h>.
typedef language_c_type clockid_t;	///< Used for clock ID type in the clock and timer functions.
typedef language_c_type dev_t;		///< Used for device IDs.
typedef language_c_type fsblkcnt_t;	///< Used for file system block counts.
typedef language_c_type fsfilcnt_t;	///< Used for file system file counts.
typedef language_c_type gid_t;		///< Used for group IDs.
typedef language_c_type id_t;		///< Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t.
typedef language_c_type ino_t;		///< Used for file serial numbers.
typedef language_c_type key_t;		///< Used for XSI interprocess communication. [Option End]
typedef language_c_type mode_t;		///< Used for some file attributes.
typedef language_c_type nlink_t;	///< Used for link counts.
typedef language_c_type off_t;		///< Used for file sizes.
typedef language_c_type pid_t;		///< Used for process IDs and process group IDs.
typedef language_c_type pthread_attr_t;			///< Used to identify a thread attribute object.

typedef language_c_type pthread_barrier_t;		///< Used to identify a barrier.
typedef language_c_type pthread_barrierattr_t;	///< Used to define a barrier attributes object.
typedef language_c_type pthread_cond_t;			///< Used for condition variables.
typedef language_c_type pthread_condattr_t;		///< Used to identify a condition attribute object.
typedef language_c_type pthread_key_t;			///< Used for thread-specific data keys.
typedef language_c_type pthread_mutex_t;		///< Used for mutexes.
typedef language_c_type pthread_mutexattr_t;	///< Used to identify a mutex attribute object.
typedef language_c_type pthread_once_t;			///< Used for dynamic package initialization.
typedef language_c_type pthread_rwlock_t;		///< Used for read-write locks.
typedef language_c_type pthread_rwlockattr_t;	///< Used for read-write lock attributes.
typedef language_c_type pthread_spinlock_t;		///< Used to identify a spin lock.
typedef language_c_type pthread_t;				///< Used to identify a thread.
typedef language_c_type size_t;		///< Used for sizes of objects.
typedef language_c_type ssize_t;	///< Used for a count of bytes or an error indication.
typedef language_c_type suseconds_t;///< Used for time in microseconds.
typedef language_c_type time_t;		///< Used for time in seconds.
typedef language_c_type timer_t;	///< Used for timer ID returned by timer_create().
typedef language_c_type trace_attr_t;		///< Used to identify a trace stream attributes object
typedef language_c_type trace_event_id_t;	///< Used to identify a trace event type.
typedef language_c_type trace_event_set_t;	///< Used to identify a trace event type set.
typedef language_c_type trace_id_t;			///< Used to identify a trace stream. 
typedef language_c_type uid_t;				///< Used for user IDs.

        
/********************************************************************************
								<aio.h> - asynchronous input and output
********************************************************************************/
class module_aio{
};

int aio_cancel (int fildes, struct aiocb *aiocbp);
int aio_error (const struct aiocb *aiocbp);
int aio_fsync (int op, struct aiocb *aiocbp);
void aio_init (const struct aioinit *init);
int aio_read (struct aiocb *aiocbp);
ssize_t aio_return (struct aiocb *aiocbp);
int aio_suspend (const struct aiocb *const list[], int nent, const struct timespec *timeout);
int aio_write (struct aiocb *aiocbp);
int lio_listio (int mode, struct aiocb *const list[], int nent, struct sigevent *sig);



/********************************************************************************
								<arpa/inet.h> - definitions for internet operations
********************************************************************************/
class module_inet{
};

uint32_t inet_addr (const char *name);
int inet_aton (const char *name, struct in_addr *addr);
uint32_t inet_lnaof (struct in_addr addr);
struct in_addr inet_makeaddr (uint32_t net, uint32_t local);
uint32_t inet_netof (struct in_addr addr) ;
uint32_t inet_network (const char *name) ;
char * inet_ntoa (struct in_addr addr);
const char * inet_ntop (int af, const void *cp, char *buf, socklen_t len);
int inet_pton (int af, const char *cp, void *buf);

int inet_aton(const char *cp, struct in_addr *inp);
in_addr_t inet_addr(const char *cp);
in_addr_t inet_network(const char *cp);
char *inet_ntoa(struct in_addr in);
struct in_addr inet_makeaddr(int net, int host);
in_addr_t inet_lnaof(struct in_addr in);

in_addr_t inet_netof(struct in_addr in);




// cpio.h         - cpio archive values
/********************************************************************************
								<cpio.h> -- 算法
********************************************************************************/
class h_cpio{
};
/* Value for the field `c_magic'.  */
#define MAGIC	"070707"

/* Values for c_mode, OR'd together: */

#define C_IRUSR		000400
#define C_IWUSR		000200
#define C_IXUSR		000100
#define C_IRGRP		000040
#define C_IWGRP		000020
#define C_IXGRP		000010
#define C_IROTH		000004
#define C_IWOTH		000002
#define C_IXOTH		000001

#define C_ISUID		004000
#define C_ISGID		002000
#define C_ISVTX		001000

#define C_ISBLK		060000
#define C_ISCHR		020000
#define C_ISDIR		040000
#define C_ISFIFO	010000
#define C_ISSOCK	0140000
#define C_ISLNK		0120000
#define C_ISCTG		0110000
#define C_ISREG		0100000


/********************************************************************************
								<dirent.h> - format of directory entries
********************************************************************************/
class h_dirent{

};
// Directorys
class module_dir{
/*
#include <sys/types.h>
#include <dirent.h>
*/
};

typedef language_c_type DIR;
struct dirent {
	unsigned short int d_reclen;
	unsigned char d_type;
	char d_name[256];		/* We must not include limits.h! */
};

///< open a directory and close a directory
DIR* opendir(const char *name);
DIR* fdopendir(int fd);
int  closedir(DIR *dirp);

/**@Brif
Example:
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
main()
{
  DIR *dir;
  struct dirent *ptr;
  int offset;
  dir = opendir("/etc/rc.d");
  while((ptr = readdir(dir)) != NULL)
  {
    offset = telldir (dir);
    printf("d_name : %s offset :%d\n", ptr->d_name, offset);
  }
  closedir(dir);
}
*/
struct dirent *readdir(DIR *dirp);
int  readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
long telldir(DIR *dirp);
void seekdir(DIR *dirp, long loc);
void rewinddir(DIR *dirp); ///< reset directory stream
int  dirfd(DIR *dirp); ///< extract the file descriptor used by a DIR stream

int rmdir(const char *pathname);
int chdir(const char *path); ///< change working directory
int link(const char *oldpath, const char *newpath);
int unlink(const char *pathname);
int rename(const char *oldpath, const char *newpath);


///< mode @Ref ref_mode_t
int mkdir (const char *path, mode_t mode);

/**@Brif
The scandir() function scans the directory dirp, calling filter() on
each directory entry.  Entries for which filter() returns nonzero are
stored in strings allocated via malloc(3), sorted using qsort(3) with
the comparison function compar(), and collected in array namelist
which is allocated via malloc(3).  If filter is NULL, all entries are selected.
relative path should reference  working dir.
Example:
   #define _DEFAULT_SOURCE
   #include <dirent.h>
   #include <stdio.h>
   #include <stdlib.h>

   int
   main(void)
   {
	   struct dirent **namelist;
	   int n;

	   n = scandir(".", &namelist, NULL, alphasort);
	   if (n == -1) {
		   perror("scandir");
		   exit(EXIT_FAILURE);
	   }

	   while (n--) {
		   printf("%s\n", namelist[n]->d_name);
		   free(namelist[n]);
	   }
	   free(namelist);

	   exit(EXIT_SUCCESS);
   }
   compar can be alphasort or versionsort or custom
*/

int scandir(const char *dirp, struct dirent ***namelist,
	   int (*filter)(const struct dirent *),
	   int (*compar)(const struct dirent **, const struct dirent **));

///< scan a directory for matching entries
/**@Brif
The alphasort() and versionsort() functions can be used as the
comparison function compar().  The former sorts directory entries
using strcoll(3), the latter using strverscmp(3) on the strings
(*a)->d_name and (*b)->d_name.
*/
int alphasort(const struct dirent **a, const struct dirent **b);
int versionsort(const struct dirent **a, const struct dirent **b);




// fcntl.h        - file control options
class h_fcntl{
};

// fenv.h         - point environment
class h_fenv{
};

// fmtmsg.h       - message display structures
class h_fmtmsg{
};
// fnmatch.h      - matching types
class h_fnmatch{

};
// ftw.h          - file tree traversal
class h_ftw{

};
// glob.h         - matching types
class h_glob{

};
// grp.h          - group structure
class h_grp{

};
// iconv.h        - codeset conversion facility
class h_iconv{

};
// langinfo.h     - language information constants
class h_langinfo{

};
// libgen.h       - definitions for pattern matching functions
class h_libgen{

};
// monetary.h     - monetary types
class h_monetary{

};
// mqueue.h       - message queues (REALTIME)
class h_mqueue{

};
// ndbm.h         - definitions for ndbm database operations
class h_ndbm{

};
// netdb.h        - definitions for network database operations
class h_netdb{

};
// net_if.h       - sockets local interfaces
class h_net_if{

};
// netinet/in.h   - Internet address family
class h_netinet_in{

};
// netinet/tcp.h  - definitions for the Internet Transmission Control Protocol (TCP)
class h_dirent{

};
// nl_types.h     - data types
class h_nl_types{

};
// poll.h         - definitions for the poll() function
class h_poll{

};

// pwd.h          - password structure
class h_pwd{

};
// regex.h        - regular expression matching types
class h_dirh_regex{

};
typedef int regoff_t;
typedef struct
{
  regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
  regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
} regmatch_t;

int regcomp(regex_t *preg, const char *regex, int cflags);
int regexec(const regex_t *preg, const char *string, size_t nmatch,regmatch_t pmatch[], int eflags);
size_t regerror(int errcode, const regex_t *preg, char *errbuf,
size_t errbuf_size);
void regfree(regex_t *preg);

// sched.h        - execution scheduling
class h_dih_sched{

};
// search.h       - search tables
class h_search{

};
// semaphore.h    - semaphores
class h_semaphore{

};
// spawn.h        - spawn (ADVANCED REALTIME)
class h_spawn{

};
// strings.h      - string operations
class h_strings{

};
// stropts.h      - STREAMS interface (STREAMS)
class h_stropts{

};
// sys/ipc.h      - XSI interprocess communication access structure
class h_sys_ipc{

};
// syslog.h       - definitions for system error logging
class h_syslog{
};
void openlog(const char *ident, int option, int facility);
void closelog(void);
void syslog(int priority, const char *format, ...);
int setlogmask(int maskpri);


// sys/mman.h     - memory management declarations
class h_sys_mman{

};
// sys/msg.h      - XSI message queue structures
class h_sys_msg{

};
// sys/resource.h - definitions for XSI resource operations
class h_sys_resource{

};
// sys/select.h   - select types
class h_sys_select{

};
// sys/sem.h      - XSI semaphore facility
class h_sys_sem{

};
// sys/shm.h      - XSI shared memory facility
class h_sys_shm{

};


class h_sys_stat{
	// @Ref module_sys_stat
	// <sys/stat.h>	  - data returned by the stat() function
	// @Ref module_sys_stat

};
// sys/statvfs.h  - VFS File System information structure
// sys/time.h     - time types
// sys/times.h    - file access and modification times structure
// sys/types.h    - data types
// sys/uio.h      - definitions for vector I/O operations
// sys/un.h       - definitions for UNIX domain sockets
// sys/utsname.h  - system name structure
// sys/wait.h     - declarations for waiting
// tar.h          - extended tar definitions
// termios.h      - define values for termios
// tgmath.h       - generic macros
// trace.h        - tracing
// utime.h        - access and modification times structure
// utmpx.h        - user accounting database definitions
// wordexp.h      - expansion types

class h_dlfcn {
// <dlfcn.h>	  - Dynamic linking
// should add link link option  -ldl  -rdynamic
// @Ref module_dlfcn
};
class h_pthread {
// <pthread.h>	   - threads
// should add link link option  -lpthread
// @Ref module_pthread
};

class module_usergroup{
};
typedef unsigned int uid_t;
typedef unsigned int gid_t;
/* The passwd structure.  */
struct passwd{
  char *pw_name;		/* Username.  */
  char *pw_passwd;		/* Password.  */
  uid_t pw_uid;			/* User ID.  */
  gid_t pw_gid;			/* Group ID.  */
  char *pw_gecos;		/* Real name.  */
  char *pw_dir;			/* Home directory.  */
  char *pw_shell;		/* Shell program.  */
};
struct group{
	char *gr_name;		/* Group name.	*/
	char *gr_passwd;		/* Password.	*/
	gid_t gr_gid;		/* Group ID.	*/
	char **gr_mem;		/* Member list.	*/
};


int setuid(uid_t uid);

int setreuid(uid_t ruid, uid_t euid);
int setregid(gid_t rgid, gid_t egid);

struct passwd *getpwent(void);

void setpwent(void);
void endpwent(void);

struct group *getgrent(void);
void setgrent(void);
void endgrent(void);


int getgroups(int size, gid_t list[]);
int setgroups(size_t size, const gid_t *list);

int setuid(uid_t uid);
uid_t getuid(void);
uid_t geteuid(void);

int setgid(gid_t gid);
gid_t getgid(void);
gid_t getegid(void);

int setfsuid(uid_t fsuid);
int setfsgid(uid_t fsgid);

int seteuid(uid_t euid);
int setegid(gid_t egid);


int initgroups(const char *user, gid_t group);

struct passwd *getpwnam(const char *name);

struct passwd *getpwuid(uid_t uid);

int getpwnam_r(const char *name, struct passwd *pwd,char *buf, size_t buflen, struct passwd **result);

int getpwuid_r(uid_t uid, struct passwd *pwd,char *buf, size_t buflen, struct passwd **result);

int getpw(uid_t uid, char *buf);


struct group *getgrnam(const char *name);

struct group *getgrgid(gid_t gid);

int getgrnam_r(const char *name, struct group *grp,char *buf, size_t buflen, struct group **result);

int getgrgid_r(gid_t gid, struct group *grp,char *buf, size_t buflen, struct group **result);
struct passwd *fgetpwent(FILE *stream);
struct group *fgetgrent(FILE *stream);

//#include <utmp.h>
struct utmp *getutent(void);
struct utmp *getutid(struct utmp *ut);
struct utmp *getutline(struct utmp *ut);

struct utmp *pututline(struct utmp *ut);

void setutent(void);
void endutent(void);

int utmpname(const char *file);


class module_signal{
};





class module_memory{
};
typedef long int		intptr_t;


/**
@Desc:allocate and free dynamic memory
@Param: size	size
@Return: allocates size bytes and returns a pointer to the allocated memory.
		The memory is not initialized.  If size is 0,then malloc() returns either NULL, 
		or a unique pointer value that can later be successfully passed to free()
@Note: #include <stdlib.h>.
**/
void* malloc(size_t size);
void  free(void *ptr);
void* calloc(size_t nmemb, size_t size);
void* realloc(void *ptr, size_t size);

/**
@Desc:allocate memory that is automatically freed
@Param: size	size
@Return: returns a pointer to the beginning of the allocated space.
		If the allocation causes stack overflow, program  behavior is undefined.
@Note: #include <alloca.h>.
The alloca() function is machine- and compiler-dependent
**/
void *alloca(size_t size);

/**
@Desc: brk() sets the end of the data segment to the value specified by addr
@Param: *addr	end of the data segment
@Return: On success, brk() returns zero.  On error, -1 is returned, and errno is set to ENOMEM.
@Note: #include <unistd.h>.
**/
int brk(void *addr);
void *sbrk(intptr_t increment);


//The function getpagesize() returns the number of bytes in a memory page, 
//where "page" is a fixed-length block, the unit for memory alloca‐tion and file 
//mapping performed by mmap
/**
@Desc:returns the number of bytes in a memory page
@Param: *nptr	digital str	
		**endptr	
		base	which must be between 2 and 36 inclusive, or be the special value 0	
@Return: The strtol() function returns the result of the conversion, 
		unless the value would underflow or overflow.  If an  underflow
		occurs,  strtol()  returns  LONG_MIN.   If  an  overflow occurs, strtol() 
		returns LONG_MAX.  In both cases, errno is set to ERANGE.
@Note: #include <stdlib.h>.
**/
int getpagesize(void);

/**
@Desc:map or unmap files or devices into memory
@Param: *addr	size
		length
		prot
		flags
		fd
		offset
@Return: returns a pointer to the beginning of the allocated space.
		If the allocation causes stack overflow, program  behavior is undefined.
@Note: #include <sys/mman.h>
The alloca() function is machine- and compiler-dependent
**/
void* mmap(  void *addr, size_t length, int prot, int flags,int fd, off_t offset);
int   munmap(void *addr, size_t length);

bcmp
bcopy
bzero
ffs
index
memccpy
memchr(const void * str, int c, size_t n)
memcmp
memcpy




class module_char{
};
//@Ref ASCII libc

class module_timedate{
};


class module_math{
};


class module_convert{
};

int toascii(int c);
toupper(int character);
tolower(int character);

/**
@Desc:converts the initial portion of the string pointed to by nptr to int
@Param: *nptr	digital str
@Return: The converted value 
@Note: #include <stdlib.h>.atoi() does not detect errors.
@Example:
#include <stdlib.h>
int main(){
	char a[] = "-100";
	char b[] = " 456";
	int c;
	c = atoi(a) + atoi(b);
	printf("c = %d \n,c");

	return 0;
}
**/

int			atoi( const char *nptr);
long 		atol( const char *nptr);
long long 	atoll(const char *nptr);
double		atof( const char *nptr);


/**
@Desc:convert a string to a long integer
@Param: *nptr	digital str	
		**endptr	
		base	which must be between 2 and 36 inclusive, or be the special value 0	
@Return: The strtol() function returns the result of the conversion, 
		unless the value would underflow or overflow.  If an  underflow
		occurs,  strtol()  returns  LONG_MIN.   If  an  overflow occurs, strtol() 
		returns LONG_MAX.  In both cases, errno is set to ERANGE.
@Note: #include <stdlib.h>.
@Example:
#include <stdlib.h>
int main(){
	char a[] = "1000000000";
	char b[] = "1000000000";
	char c[] = " ffff";

	printf("a = %d \n,strtol(a,NULL,0)");
	printf("b = %d \n,strtol(b,NULL,2)");
	printf("c = %d \n,strtol(c,NULL,16)");

	return 0;
}
**/
long int 				strtol(  const char *nptr, char **endptr, int base);
long long int			strtoll( const char *nptr, char **endptr, int base);
unsigned long int		strtoul( const char *nptr, char **endptr, int base);
unsigned long long int  strtoull(const char *nptr, char **endptr, int base);


/**
@Desc:convert ASCII string to floating-point number.
@Param: *nptr 
		**endptr
@Return: returns the address of the string pointed to by buf
@Note: #include <stdlib.h>.
@Example:
#include <stdlib.h>
int main(){
	double a = 123.45;
	double b = -1234.56;
	char buf[256];
	char *ptr;
	int decpy,sign;
	gcvt(a,5,buf);
	printf("a value = %s\n",buf);
	ptr = gcvt(b,6,buf);
	printf("b value = %s\n",ptr);

	return 0;
}
**/

double		strtod(	const char *nptr, char **endptr);
float		strtof(	const char *nptr, char **endptr);
long double	strtold(const char *nptr, char **endptr);

/**
@Desc:convert a floating-point number to a string.
@Param: number   handle returned by dlopen 
		ndigit   width
		*buf    buf used to store convert string
@Return: returns the address of the string pointed to by buf
@Note: #include <stdlib.h>.
@Example:
#include <stdlib.h>
int main(){
	double a = 123.45;
	double b = -1234.56;
	char buf[256];
	char *ptr;
	int decpy,sign;
	gcvt(a,5,buf);
	printf("a value = %s\n",buf);
	ptr = gcvt(b,6,buf);
	printf("b value = %s\n",ptr);

	return 0;
}
**/
char* gcvt(double number, size_t ndigit, char *buf);

/**
@Desc:convert a floating-point number to a string
@Param: number   handle returned by dlopen 
		ndigits   width
		*decpt    buf used to store convert string
		*sign    buf used to store convert string		
@Return: returns the address of the string pointed to by buf
@Note: #include <stdlib.h>.
@Example:
#include <stdlib.h>
int main(){
	double a = 123.45;
	double b = -1234.56;
	char buf[256];
	char *ptr;
	int decpy,sign;
	gcvt(a,5,buf);
	printf("a value = %s\n",buf);
	ptr = gcvt(b,6,buf);
	printf("b value = %s\n",ptr);

	return 0;
}
**/
char* ecvt(double number, int ndigits, int *decpt, int *sign);
char* fcvt(double number, int ndigits, int *decpt, int *sign);


class module_interface{
};


// Files
class module_file{
};

struct stat {
	unsigned long	st_dev;		/* Device.  */
	unsigned long	st_ino;		/* File serial number.  */
	unsigned int	st_mode;	/* File mode.  */
	unsigned int	st_nlink;	/* Link count.  */
	unsigned int	st_uid;		/* User ID of the file's owner.  */
	unsigned int	st_gid;		/* Group ID of the file's group. */
	unsigned long	st_rdev;	/* Device number, if device.  */
	unsigned long	__pad1;
	long		    st_size;	/* Size of file, in bytes.  */
	int		        st_blksize;	/* Optimal block size for I/O.  */
	int		        __pad2;
	long		    st_blocks;	/* Number 512-byte blocks allocated. */
	long		    st_atime;	/* Time of last access.  */
	unsigned long	st_atime_nsec;
	long		    st_mtime;	/* Time of last modification.  */
	unsigned long	st_mtime_nsec;
	long		    st_ctime;	/* Time of last status change.  */
	unsigned long	st_ctime_nsec;
	unsigned int	__unused4;
	unsigned int	__unused5;
};

int open(const char *pathname, int flags);
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
int access(const char *pathname, int mode);
int creat(const char *pathname, mode_t mode);
int close(int fd);
FILE *fdopen(int fildes, const char *mode);
int fileno(FILE *stream);
///<  #include <sys/stat.h>  
int stat(const char *restrict path, struct stat *restrict buf);


class module_env{
};


class module_terminal{
};


class module_process{
};
typedef int  pid_t;

int system (const char *string);
int kill(pid_t pid, int sig);
unsigned int sleep(unsigned int seconds);
int pause(void);

/**
@Desc:cause normal process termination.	
@Param: 	status  the value of status & 0377 is returned to the parent 
@Return: The exit() function does not return  
@Note: #include <stdlib.h>         
**/
void exit(int status);
unsigned int alarm(unsigned int seconds);


int execl(const char *path, const char *arg, ...);
int execle(const char *path, const char *arg, ..., char * const envp[]);
int execv  (const char *path, char *const argv[]);	   

int execlp(const char *file, const char *arg, ...);
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[],char *const envp[]);

/**
@Desc:create a child process.	
@Return: // creates  a  new process by duplicating the calling process.  The new process, referred to as the child, is an exact
// duplicate of the calling process, referred to as the parent, except for the following points:
@Note: #include <stdlib.h>
/**
Example:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
	pid_t pid;
	char *message;
	int n;
	printf("fork program starting\n");
	pid = fork();
	switch(pid)
	{
		case −1:
			perror("fork failed");
			exit(1);
		case 0:
			message = "This is the child";
			n = 5;
		break;
		default:
			message = "This is the parent";
			n = 3;
		break;
	}
	for(; n > 0; n−−) {
		puts(message);
		sleep(1);
	}
	exit(0);
}
**/
pid_t fork(void);



pid_t wait(int *stat_loc);
pid_t waitpid(pid_t pid, int *stat_loc, int options);
int   kill(pid_t pid, int sig);



class module_permission{
};

int chmod(const char *path, mode_t mode);
int chown(const char *path, uid_t owner, gid_t group);
int utime(const char *filename, struct utimbuf *buf);



// Files and Directories <Advance>


int fcntl(int fd, int cmd);
int fstat(int filedes, struct stat *buf);
off_t lseek(int fildes, off_t offset, int whence);
int dup(int oldfd);
int dup2(int oldfd, int newfd);
int pipe(int filedes[2]);

mode_t umask(mode_t mask);





class module_linux_misc{
};
#define __NEW_UTS_LEN 64
struct new_utsname {
	char sysname[__NEW_UTS_LEN + 1];
	char nodename[__NEW_UTS_LEN + 1];
	char release[__NEW_UTS_LEN + 1];
	char version[__NEW_UTS_LEN + 1];
	char machine[__NEW_UTS_LEN + 1];
	char domainname[__NEW_UTS_LEN + 1];
};

int gethostname(char *name, size_t len); // #include <unistd.h>
int sethostname(const char *name, size_t len);// #include <unistd.h>

int uname(struct utsname *name);
long gethostid(void);
char *getcwd(char *buf, size_t size);

char *getenv(const char *name); 
int putenv(const char *string); 

/**
@Desc:parse command options (enhanced).
@Param: 	*addr   return so address  
			*info   return Dl_info
@Return:   
@Note: #include <dlfcn.h> Link with -ldl.  

Example:
#include <ctype.h>
#include "tlpi_hdr.h"
#define printable(ch) (isprint((unsigned char) ch) ? ch : '#')
// Print "usage" message and exit
static void usageError(char *progName, char *msg, int opt){
	if (msg != NULL && opt != 0)
	fprintf(stderr, "%s (-%c)\n", msg, printable(opt));
	fprintf(stderr, "Usage: %s [-p arg] [-x]\n", progName);
	exit(EXIT_FAILURE);
}

int main(int argc, char *argv[]){
	int opt, xfnd;
	char *pstr;
	xfnd = 0;
	pstr = NULL;
	while ((opt = getopt(argc, argv, ":p:x")) != -1) {
		printf("opt =%3d (%c); optind = %d", opt, printable(opt), optind);
		if (opt == '?' || opt == ':')
		printf("; optopt =%3d (%c)", optopt, printable(optopt));
		printf("\n");
		switch (opt) {
			case 'p': pstr = optarg; break;
			case 'x': xfnd++; break;
			case ':': usageError(argv[0], "Missing argument", optopt);
			case '?': usageError(argv[0], "Unrecognized option", optopt);
			default: fatal("Unexpected case in switch()");
		}
	}
	if (xfnd != 0)
	printf("-x was specified (count=%d)\n", xfnd);
	if (pstr != NULL)
	printf("-p was specified with the value \"%s\"\n", pstr);
	if (optind < argc)
	printf("First nonoption argument is \"%s\" at argv[%d]\n",
	argv[optind], optind);
	exit(EXIT_SUCCESS);
}
**/
int getopt(int argc, char *const argv[], const char *optstring);




char *tmpnam(char *s);
FILE *tmpfile(void);
char *mktemp(char *template);
int mkstemp(char *template);

uid_t getuid(void);
char *getlogin(void);
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
void endpwent(void);
struct passwd *getpwent(void);
void setpwent(void);
uid_t geteuid(void);
gid_t getgid(void);
gid_t getegid(void);
int setuid(uid_t uid);
int setgid(gid_t gid);




pid_t getpid(void);
pid_t getppid(void);
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int priority);
int getrlimit(int resource, struct rlimit *r_limit);
int setrlimit(int resource, const struct rlimit *r_limit);
int getrusage(int who, struct rusage *r_usage);





/**
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *var, *value;
if(argc == 1 || argc > 3) {
fprintf(stderr,"usage: environ var [value]\n");
exit(1);
}
var = argv[1];
value = getenv(var);
if(value)
printf("Variable %s has value %s\n", var, value);
else
printf("Variable %s has no value\n", var);
**/





typedef unsigned int  mode_t;

class h_sys_stat{	
};

#define S_IFMT   00170000
#define S_IFSOCK 0140000
#define S_IFLNK	 0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000   // set-user-ID (set process effective user ID on execve(2))
#define S_ISGID  0002000   // set-group-ID	(set  process effective group ID on execve(2); mandatory locking, as described in fcntl(2);
#define S_ISVTX  0001000   // set-group-ID	(set  process effective group ID on execve(2); mandatory locking, as described in fcntl(2);


#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)

// mode_t value
class ref_mode_t{};

#define S_IRWXU 00700 // read、write、execute by owner
#define S_IRUSR 00400 // read by owner
#define S_IWUSR 00200 // write by owner
#define S_IXUSR 00100 // execute/search by owner

#define S_IRWXG 00070 // read、write、execute by group
#define S_IRGRP 00040 // read by group
#define S_IWGRP 00020 // write by group
#define S_IXGRP 00010 // execute/search by group

#define S_IRWXO 00007 // read、write、execute by others
#define S_IROTH 00004 // read by others
#define S_IWOTH 00002 // write by others
#define S_IXOTH 00001 // execute/search by others


int chmod (const char *path, mode_t mode);
int fchmod(int fd, mode_t mode);




/**
POSIX Threads  
@Ref https://man7.org/linux/man-pages/dir_all_by_section.html
@Ref https://computing.llnl.gov/tutorials/pthreads/#Management

#include <pthread.h>
Compile and link with -pthread.
pthread_			Threads themselves and miscellaneous subroutines
pthread_attr_		Thread attributes objects
pthread_mutex_		Mutexes
pthread_mutexattr_	Mutex attributes objects.
pthread_cond_		Condition variables
pthread_condattr_	Condition attributes objects
pthread_key_		Thread-specific data keys
pthread_rwlock_		Read/write locks
pthread_barrier_	Synchronization barriers
**/

class module_pthread{
};



struct sched_param
{
	int __sched_priority;
};



/**
Example:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>

void *thread_function(void *arg);
char message[] = "Hello World";

int main() {
	int res;
	pthread_t a_thread;
	void *thread_result;
	res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
	if (res != 0) {
		perror("Thread creation failed");
		exit(EXIT_FAILURE);
	}
	printf("Waiting for thread to finish...\n");
	res = pthread_join(a_thread, &thread_result);
	if (res != 0) {
		perror("Thread join failed");
		exit(EXIT_FAILURE);
	}
	printf("Thread joined, it returned %s\n", (char *)thread_result);
	printf("Message is now %s\n", message);
	exit(EXIT_SUCCESS);
}

void *thread_function(void *arg) {
	printf("thread_function is running. Argument was %s\n", (char *)arg);
	sleep(3);
	strcpy(message, "Bye!");
	pthread_exit("Thank you for the CPU time");
}
**/
///< create a new thread
int  pthread_create(pthread_t *thread, const pthread_attr_t *attr,void *(*start_routine) (void *), void *arg); 
///< send a cancellation request to a thread
int  pthread_cancel(pthread_t thread);
///< wait for thread termination
void pthread_exit(void *retval);
int  pthread_join(pthread_t th, void **thread_return);
/**@brif
causes the calling thread to relinquish the CPU. The thread is placed at the end of the run queue 
for its static priority and another thread is scheduled to run.
*/
int pthread_yield(void);

/**@brif
When a detached thread terminates, its resources are automatically released back to the system 
without the need for another thread to join with the terminated thread.
**/
int  pthread_detach(pthread_t thread);
///< If the two thread IDs are equal, pthread_equal() returns a nonzero value; otherwise, it returns 0.
int  pthread_equal(pthread_t t1, pthread_t t2);


int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype (int type, int *oldtype);

/**@brief
initialize and destroy thread attributes object
destroy and initialize the thread attributes object
*/
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_destroy(pthread_attr_t *attr);

/**@brief set/get CPU affinity attribute in thread attributes object */
int pthread_attr_setaffinity_np(pthread_attr_t *attr,size_t cpusetsize, const cpu_set_t *cpuset);
int pthread_attr_getaffinity_np(const pthread_attr_t *attr,size_t cpusetsize, cpu_set_t *cpuset);

/**@brief set/get detach state attribute in thread attributes object */
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);

/**@brief set/get guard size attribute in thread attributes object */
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);


/**@brief set/get inherit-scheduler attribute in thread attributes object */
int pthread_attr_setinheritsched(pthread_attr_t *attr,int inheritsched);
int pthread_attr_getinheritsched(const pthread_attr_t *attr,int *inheritsched);


/**@brief set/get scheduling parameter attributes in thread attributes object */
int pthread_attr_setschedparam(pthread_attr_t *attr,const struct sched_param *param);
int pthread_attr_getschedparam(const pthread_attr_t *attr,struct sched_param *param);


/**@brief set/get scheduling policy attribute in thread attributes object */
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);

/// set/get contention scope attribute in thread attributes object
int pthread_attr_setscope(pthread_attr_t *attr, int scope);
int pthread_attr_getscope(const pthread_attr_t *attr, int *scope);

/// set/get signal mask attribute in thread attributes object
int pthread_attr_setsigmask_np(pthread_attr_t *attr,const sigset_t *sigmask);
int pthread_attr_getsigmask_np(const pthread_attr_t *attr,sigset_t *sigmask);

/**@brief set/get stack attributes in thread attributes object */
int pthread_attr_setstack(pthread_attr_t *attr,void *stackaddr, size_t stacksize);
int pthread_attr_getstack(const pthread_attr_t *attr,void **stackaddr, size_t *stacksize);

/**@brief set/get stack address attribute in thread attributes object */
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);

///< set/get stack size attribute in thread attributes object
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);



int pthread_mutex_init   (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);
int pthread_mutex_destroy(pthread_mutex_t *mutex);

int pthread_mutex_lock   (pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_timedlock(pthread_mutex_t *restrict mutex,const struct timespec *restrict abstime);
int pthread_mutex_unlock(pthread_mutex_t *mutex);

int pthread_mutex_consistent(pthread_mutex_t *mutex);
int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict mutex,int *restrict prioceiling);
int pthread_mutex_setprioceiling(pthread_mutex_t *restrict mutex,int prioceiling, int *restrict old_ceiling);


int pthread_mutexattr_init(pthread_mutexattr_t *attr);
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);

int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t*restrict attr, int *restrict prioceiling);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,int prioceiling);

int pthread_mutexattr_getprotocol(const pthread_mutexattr_t*restrict attr, int *restrict protocol);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,int protocol);

int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,int *pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,int pshared);

int pthread_mutexattr_getrobust(const pthread_mutexattr_t *attr,int *robustness);
int pthread_mutexattr_setrobust(const pthread_mutexattr_t *attr,int robustness);

int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,int *restrict type);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);

int pthread_mutexattr_getrobust(const pthread_mutexattr_t *attr,int *robustness);
int pthread_mutexattr_setrobust(const pthread_mutexattr_t *attr,int robustness);


/**@brif 
registers fork handlers that are to be executed when fork  is called by this thread
*/
int pthread_atfork(void (*prepare)(void), void (*parent)(void),void (*child)(void));




/// pthread_barrier

int pthread_barrier_init(pthread_barrier_t *restrict barrier,const pthread_barrierattr_t *restrict attr, unsigned count);
int pthread_barrier_destroy(pthread_barrier_t *barrier);

int pthread_barrierattr_init(pthread_barrierattr_t *attr);
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);

int pthread_barrierattr_getpshared(const pthread_barrierattr_t*restrict attr, int *restrict pshared);
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr,int pshared);
int pthread_barrier_wait(pthread_barrier_t *barrier);

void pthread_cleanup_push(void (*routine)(void *),void *arg);
void pthread_cleanup_pop(int execute);

void pthread_cleanup_push_defer_np(void (*routine)(void *), void *arg);
void pthread_cleanup_pop_restore_np(int execute);


/**
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
*/
int pthread_cond_init(pthread_cond_t *restrict cond,const pthread_condattr_t *restrict attr);
int pthread_cond_destroy(pthread_cond_t *cond);

int pthread_cond_timedwait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex,const struct timespec *restrict abstime);
int pthread_cond_wait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex);

int pthread_cond_broadcast(pthread_cond_t *cond);
int pthread_cond_signal(pthread_cond_t *cond);

int pthread_condattr_init(pthread_condattr_t *attr);
int pthread_condattr_destroy(pthread_condattr_t *attr);

int pthread_condattr_getclock(const pthread_condattr_t *restrict attr,clockid_t *restrict clock_id);
int pthread_condattr_setclock(pthread_condattr_t *attr,clockid_t clock_id);

int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr,int *restrict pshared);
int pthread_condattr_setpshared(pthread_condattr_t *attr,int pshared);



int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize,const cpu_set_t *cpuset);
int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize,cpu_set_t *cpuset);

int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr);

int pthread_getattr_default_np(pthread_attr_t *attr);
int pthread_setattr_default_np(pthread_attr_t *attr);

int pthread_setconcurrency(int new_level);
int pthread_getconcurrency(void);

// retrieve ID of a thread's CPU time clock
int pthread_getcpuclockid(pthread_t thread, clockid_t *clockid);

int pthread_setname_np(pthread_t thread, const char *name);
int pthread_getname_np(pthread_t thread,char *name, size_t len);

int pthread_setschedparam(pthread_t thread, int policy,const struct sched_param *param);
int pthread_getschedparam(pthread_t thread, int *policy,struct sched_param *param);


void *pthread_getspecific(pthread_key_t key);
int   pthread_setspecific(pthread_key_t key, const void *value);

int  pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
int  pthread_key_delete(pthread_key_t key);

int  pthread_kill(pthread_t thread, int sig);
void pthread_kill_other_threads_np(void);



///< destroy and initialize the read-write lock attributes object
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);

int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr,int pref);
int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *attr,int *pref);

int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*restrict attr, int *restrict pshared);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,int pshared);


///< pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,const pthread_rwlockattr_t *restrict attr);
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);

int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);

int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);

int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rwlock,const struct timespec *restrict abstime);
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rwlock,const struct timespec *restrict abstime);

int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);

pthread_t pthread_self(void);
int pthread_setschedprio(pthread_t thread, int prio);
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
int pthread_setspecific(pthread_key_t key, const void *value);
int pthread_sigqueue(pthread_t thread, int sig,const union sigval value);

int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
int pthread_spin_destroy(pthread_spinlock_t *lock);

int pthread_spin_lock(pthread_spinlock_t *lock);
int pthread_spin_trylock(pthread_spinlock_t *lock);
int pthread_spin_unlock(pthread_spinlock_t *lock);

///< request delivery of any pending cancellation request
void pthread_testcancel(void);

int pthread_tryjoin_np(pthread_t thread, void **retval);
int pthread_timedjoin_np(pthread_t thread, void **retval,const struct timespec *abstime);

//pthread_once_t once_control = PTHREAD_ONCE_INIT;
int pthread_once(pthread_once_t *once_control,void (*init_routine)(void));




class module_pthread_sync{
};

typedef language_c_type sem_t;

int sem_init(sem_t *sem, int pshared, unsigned int value);
int sem_destroy(sem_t * sem);
int sem_post(sem_t * sem);

int sem_wait(sem_t *sem);
int sem_trywait(sem_t *sem);
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);

// sem_t *sem_open(const char *name, int oflag,mode_t mode, unsigned int value);
sem_t* sem_open (const char *name, int oflag, ...);
int sem_close(sem_t *sem);
int sem_getvalue(sem_t *sem, int *sval);
int sem_unlink(const char *name);	 // remove a named semaphore

// IPC 	Signal 
// #include <signal.h>

class module_IPC_signal{
};

typedef language_c_type sigset_t;

int sigaddset  (sigset_t *set, int signo);
int sigemptyset(sigset_t *set);
int sigfillset (sigset_t *set);

int sigemptyset(sigset_t *set);
int sigismember(const sigset_t *set, int signum);	
int sigfillset(sigset_t *set);
int sigaddset(sigset_t *set, int signum);
int sigdelset(sigset_t *set, int signum);

int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
int sigpending(sigset_t *set);
int sigsuspend(const sigset_t *sigmask);





//IPC: Pipes
//#include <stdio.h>

class module_IPC_pipes{
};
FILE *popen(const char *command, const char *open_mode);
int pclose(FILE *stream_to_close);


class module_IPC_fifo{
};
int mkfifo(const char *pathname, mode_t mode);


//accept(2),	bind(2),  connect(2),  fcntl(2),  getpeername(2),  getsockname(2), getsockopt(2), ioctl(2), listen(2), read(2),
//recv(2), select(2), send(2), shutdown(2),  socketpair(2),  write(2),  getprotoent(3),  ip(7),  socket(7),  tcp(7),	udp(7),
//unix(7)

class module_IPC_sockets {
};


typedef unsigned short int sa_family_t;
typedef unsigned int       in_addr_t;
typedef long int           ssize_t;
typedef unsigned int       socklen_t;
typedef language_c_type sockaddr;

struct in_addr {
	unsigned long int s_addr;
};

struct sockaddr_un {
	sa_family_t sun_family; /* AF_UNIX */
	char sun_path[]; /* pathname */
};

struct sockaddr_in {
	short int sin_family; /* AF_INET */
	unsigned short int sin_port; /* Port number */
	struct in_addr sin_addr; /* Internet address */
};

struct msghdr{
	void *msg_name;		/* Address to send to/receive from.  */
	socklen_t msg_namelen;	/* Length of address data.  */

	struct iovec *msg_iov;	/* Vector of data to send/receive into.  */
	size_t msg_iovlen;		/* Number of elements in the vector.  */

	void *msg_control;		/* Ancillary data (eg BSD filedesc passing). */
	size_t msg_controllen;	/* Ancillary data buffer length.
							   !! The type should be socklen_t but the
							   definition of the kernel is incompatible
							   with this.  */

	int msg_flags;		/* Flags on received message.  */
};

#define ref_socket_domain

//Name						Purpose 						 Man page
#define	AF_LOCAL 			//Local communication 			 unix(7)
#define	AF_UNIX				//Local communication 			 unix(7)
#define	AF_INET 			//IPv4 Internet protocols 		 ip(7)
#define	AF_INET6			//IPv6 Internet protocols 		 ipv6(7)
#define	AF_IPX				//IPX - Novell protocols
#define	AF_NETLINK			//Kernel user interface device	 netlink(7)
#define	AF_X25				//ITU-T X.25 / ISO-8208 protocol x25(7)
#define	AF_AX25 			//Amateur radio AX.25 protocol
#define	AF_ATMPVC			//Access to raw ATM PVCs
#define	AF_APPLETALK		//Appletalk						 ddp(7)
#define	AF_PACKET			//Low level packet interface		 packet(7)

#define ref_socket_type {}


#define SOCK_STREAM 	
//Provides sequenced, reliable, two-way, connection-based byte streams.
//An	out-of-band  data  transmission mechanism may be supported.

#define SOCK_DGRAM	  
//Supports datagrams (connectionless, unreliable messages of a fixed maximum length).

#define SOCK_SEQPACKET  
//Provides a sequenced, reliable, two-way connection-based data transmission path for 
//datagrams of fixed max‐imum length; a consumer is required to read an entire packet with each input system call.
//SOCK_SEQPACKET is not implemented for AF_INET

#define SOCK_RAW		  
//Provides raw network protocol access.

#define SOCK_RDM		  
//Provides a reliable datagram layer that does not guarantee ordering.

#define SOCK_PACKET	  
//Obsolete and should not be used in new programs; see packet(7).


#define SOCK_NONBLOCK   
//Set the O_NONBLOCK file status flag on the new open file description.  
//Using this flag saves extra calls to fcntl(2) to achieve the same result.

#define SOCK_CLOEXEC	  
//Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor.  
//See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful.


#define ref_socket_protocol {}

/**
@Desc:creates an endpoint for communication and returns a descriptor.	
@Param: 	domain   @Ref{ ref_socket_domain }   The  domain argument specifies a communication domain
			type     @Ref{ ref_socket_type }  this selects the protocol family which will be used for communication
			protocol @Ref{ ref_socket_protocol }
@Return: On success, a file descriptor for the new socket is returned.  
         On error, -1 is returned, and errno is set appropriately. 
         @Ref{ref_errno_base}       
**/
int socket (int domain, int type, int protocol);


int accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bind   (int sockfd, const struct sockaddr *addr,socklen_t addrlen);
int connect(int sockfd, const struct sockaddr *addr,socklen_t addrlen);
int listen (int sockfd, int backlog);


int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int getsockopt (int sockfd, int level, int optname,void *optval, socklen_t *optlen);
int setsockopt (int sockfd, int level, int optname,const void *optval, socklen_t optlen);

ssize_t recv    (int sockfd, void *buf, size_t len, int flags);
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,struct sockaddr *src_addr, socklen_t *addrlen);
ssize_t recvmsg (int sockfd, struct msghdr *msg, int flags);

ssize_t send   (int sockfd, const void *buf, size_t len, int flags);
ssize_t sendto (int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr, socklen_t addrlen);
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);

int shutdown  (int sockfd, int how);
int sockatmark(int sockfd);
int socketpair(int domain, int type, int protocol, int sv[2]);




class module_dlfcn {
};

/**
Example:
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

int main(int argc, char **argv)
{
	void *handle;
	double (*cosine)(double);
	char *error;

	handle = dlopen("libm.so", RTLD_LAZY);
	if (!handle) {
	   fprintf(stderr, "%s\n", dlerror());
	   exit(EXIT_FAILURE);
	}

	dlerror();    // Clear any existing error

	//Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
	//would seem more natural, but the C99 standard leaves
	//casting from "void *" to a function pointer undefined.
	//The assignment used below is the POSIX.1-2003 (Technical
	//Corrigendum 1) workaround; see the Rationale for the
	//POSIX specification of dlsym(). 

	*(void **) (&cosine) = dlsym(handle, "cos");

	if ((error = dlerror()) != NULL)  {
	   fprintf(stderr, "%s\n", error);
	   exit(EXIT_FAILURE);
	}

	printf("%f\n", (*cosine)(2.0));
	dlclose(handle);
	exit(EXIT_SUCCESS);
}
**/
#define ref_dlfcn_flag {}

/* The MODE argument to `dlopen' contains one of the following: */
#define RTLD_LAZY	0x00001	/* Lazy function call binding.  */
#define RTLD_NOW	0x00002	/* Immediate function call binding.  */
#define	RTLD_BINDING_MASK   0x3	/* Mask of binding time value.  */
#define RTLD_NOLOAD	0x00004	/* Do not load the object.  */
#define RTLD_DEEPBIND	0x00008	/* Use deep binding.  */

/* If the following bit is set in the MODE argument to `dlopen',
   the symbols of the loaded object and its dependencies are made
   visible as if the object were linked directly into the program.  */
#define RTLD_GLOBAL	0x00100

/* Unix98 demands the following flag which is the inverse to RTLD_GLOBAL.
   The implementation does this by default and so we can define the
   value to zero.  */
#define RTLD_LOCAL	0

/* Do not delete object when closed.  */
#define RTLD_NODELETE	0x01000



typedef struct {
	const char	*dli_fname;  /* Pathname of shared object that contains address */
	void		*dli_fbase;  /* Address at which shared object is loaded */
	const char	*dli_sname;  /* Name of nearest symbol with address lower than addr */
	void		*dli_saddr;  /* Exact address of symbol named in dli_sname */
} Dl_info;


/**
@Desc:loads the dynamic library file named by the null-terminated string 
		filename and returns an opaque"handle" for the dynamic library.	
@Param: 	filename   so file path  
			flag       @Ref{ ref_dlfcn_flag } 
@Return: fails for any reason, it returns NULL. 
@Note: #include <dlfcn.h> Link with -ldl.
**/
void *dlopen (const char *filename, int flag);


/**
@Desc:returns  a  human  readable  string describing the most recent error.
		that occurred from dlopen(), dlsym() or dlclose()
@Return: It returns NULL if no errors have occurred  
@Note: #include <dlfcn.h> Link with -ldl.         
**/
char *dlerror(void);


/**
@Desc:creates an endpoint for communication and returns a descriptor.	
@Param: 	*handle   a "handle" of a dynamic library returned by dlopen() 
			*symbol   the null-terminated symbol name
@Return: returning the address where that symbol is loaded into memory.  
@Note: #include <dlfcn.h> Link with -ldl.         
**/
void *dlsym  (void *handle, const char *symbol);

/**
@Desc:decrements the reference count on the dynamic library handle handle.  
		If the reference count  drops  to  zero  and  no  other  loaded 
		libraries use symbols in it, then the dynamic library is unloaded.
@Param: *handle   handle returned by dlopen 
@Return: returns 0 on success, and nonzero on error. @Ref{ref_errno_base}
@Note: #include <dlfcn.h> Link with -ldl.         
**/
int   dlclose(void *handle);

/**
@Desc:returns 0 on error, and nonzero on success.
@Param: 	*addr   return so address  
			*info   return Dl_info
@Return:   
@Note: #include <dlfcn.h> Link with -ldl.         
**/
int dladdr(void *addr, Dl_info *info);


class module_algorithm {
};

typedef struct entry{
	char *key;
	void *data;
}ENTRY;

typedef enum
{
	FIND,
	ENTER
}ACTION;

int   rand(void);

void  srand(unsigned int seed);

/**
@Desc:sorts an array with nmemb elements of size size
@Param: 	*base   return so address  
			nmemb   return Dl_info
			size
			compar
@Return:none
@Note: #define _XOPEN_SOURCE #include <unistd.h> Link with -lcrypt.
**/
void  qsort(void *base, size_t nmemb, size_t size,int (*compar)(const void *, const void *));

void  qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *),void *arg);

void* bsearch(const void *key, const void *base,size_t nmemb, size_t size,int (*compar)(const void *, const void *));

void* tsearch(const void *key, void **rootp,int (*compar)(const void *, const void *));

void* tfind(const void *key, const void **rootp,int (*compar)(const void *, const void *));

void* tdelete(const void *key, void **rootp,int (*compar)(const void *, const void *));

void  twalk(const void *root, void (*action)(const void* nodep,const VISIT which,const int depth));

void  tdestroy(void *root, void (*free_node)(void *nodep));

//linear search of an array

void* lfind(const void *key, const void *base, size_t *nmemb,size_t size, int(*compar)(const void *, const void *));

void* lsearch(const void *key, void *base, size_t *nmemb,size_t size, int(*compar)(const void *, const void *));


/**
@Desc:sorts an array with nmemb elements of size size
@Param: 	*base   return so address  
			nmemb   return Dl_info
			size
			compar
@Return:none
@Note: #include <search.h>  only one hash table can be used at a time
@Example:
#include <stdio.h>
#include <stdlib.h>
#include <search.h>

char *data[] = { "alpha", "bravo", "charlie", "delta",
    "echo", "foxtrot", "golf", "hotel", "india", "juliet",
    "kilo", "lima", "mike", "november", "oscar", "papa",
    "quebec", "romeo", "sierra", "tango", "uniform",
    "victor", "whisky", "x-ray", "yankee", "zulu"
};

int
main(void)
{
   ENTRY e, *ep;
   int i;

   hcreate(30);

   for (i = 0; i < 24; i++) {
       e.key = data[i];
       // data is just an integer, instead of a
       //   pointer to something 
       e.data = (void *) i;
       ep = hsearch(e, ENTER);
       // there should be no failures 
       if (ep == NULL) {
           fprintf(stderr, "entry failed\n");
           exit(EXIT_FAILURE);
       }
   }

   for (i = 22; i < 26; i++) {
          //print two entries from the table, and
          //show that two are not in the table 
       e.key = data[i];
       ep = hsearch(e, FIND);
       printf("%9.9s -> %9.9s:%d\n", e.key,
              ep ? ep->key : "NULL", ep ? (int)(ep->data) : 0);
   }
   hdestroy();
   exit(EXIT_SUCCESS);
}
**/
int hcreate(size_t nel);

ENTRY *hsearch(ENTRY item, ACTION action);

void hdestroy(void);



#define _GNU_SOURCE		 /* See feature_test_macros(7) */
#include <search.h>

int hcreate_r(size_t nel, struct hsearch_data *htab);

int hsearch_r(ENTRY item, ACTION action, ENTRY **retval,struct hsearch_data *htab);

void hdestroy_r(struct hsearch_data *htab);


/**
@Desc:returns 0 on error, and nonzero on success.
@Param: 	*key   return so address  
			*salt   return Dl_info
@Return:   
@Note: #define _XOPEN_SOURCE #include <unistd.h> Link with -lcrypt.
**/
char* crypt(const char *key, const char *salt);


/**
@Desc:returns 0 on error, and nonzero on success.
@Param: 	*addr   return so address  
			*info   return Dl_info
@Return:   
@Note: #define _GNU_SOURCE  #include <crypt.h> Link with -lcrypt.
**/
char* crypt_r(const char *key, const char *salt,struct crypt_data *data);




#endif

//end of file
